package com.store.controller;

import com.store.entity.Product;
import com.store.service.IProductService;
import com.store.util.JsonResult;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cai
 * @since 2022-07-13
 */
@RestController
@RequestMapping("products")
public class ProductController extends BaseController {
    @Autowired
    IProductService iProductService;

    @RequestMapping("hot_list")
    public JsonResult<List<Product>> getHotList(){
        List<Product> data =iProductService.showHotProduct();
        return new JsonResult<List<Product>>(OK,data);
    }

    @RequestMapping("{id}/details")
    public JsonResult<Product> getById(@PathVariable("id") Integer id){
        Product product =iProductService.myGetById(id);
        return new JsonResult<Product>(OK,product);
    }
}
